<template>
    <a-button @click="follow" :type="user.follow ? 'default' : 'primary'">{{ user.follow ? '已关注' : '关注'}}</a-button>
</template>

<script setup lang="ts">
import request from '@/script/utils/request'; // 导入Axios实例

const props = defineProps({
    user: {
        type: Object
    }
});

//关注/取消关注
const follow = () => {
    const user = props.user;
    if (user.follow) {
        //取消关注
        try {
            request.post(`/user/cancel-follow`, {
                targetUserId: user.id
            })
            user.follow = false;
            // user.likeCount--;
        } catch (e) {

        }
    } else {
        try {
            //点关注
            request.post(`/user/follow`, {
                targetUserId: user.id
            })
            user.follow = true;
            // user.likeCount--;
        } catch (e) {

        }

    }
}
</script>
